package com.ffcs.cn.action.desktopcontrol.warnorhelpprovider;

import com.supermap.desktop.controls.ui.controls.ProviderLabel.ProviderType;
import com.supermap.desktop.controls.ui.controls.ProviderLabel.WarningOrHelpProvider;
import com.supermap.desktop.controls.ui.controls.SmDialog;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;
import com.supermap.desktop.core.utilties.BrowserUtilities;

import java.awt.*;

/**
 * 警告与提示标签的示例对话框
 *
  */
public class DialogWarningOrHelpProvider extends SmDialog {
	private WarningOrHelpProvider helpProvider;
	private WarningOrHelpProvider warningProvider;

	public DialogWarningOrHelpProvider() {
		initComponents();
		initLayout();
		registerEvents();
	}

	private void initComponents() {
		setSize(new Dimension(300, 100));
		setTitle("警告与提示标签");
		warningProvider = new WarningOrHelpProvider("警告", ProviderType.WARNING);
		helpProvider = new WarningOrHelpProvider("提示", ProviderType.HELP);
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		this.add(helpProvider, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(0, 0)
				.setFill(GridBagConstraints.CENTER));
		this.add(warningProvider, new GridBagConstraintsHelper(1, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(0, 0)
				.setFill(GridBagConstraints.CENTER));
	}

	private void registerEvents() {
		helpProvider.addClickListener(e -> BrowserUtilities.openUrl("https://www.supermap.com"));
	}
}
